package jdbc;

import com.mysql.cj.protocol.Resultset;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Scanner;

public class LoginDemo {
    public static void main(String[] args) {
        try (Connection conn = DBUtil.getConnection();){
            Scanner is = new Scanner(System.in);
            System.out.println("请输入用户名：");
            String username = is.nextLine();
            System.out.println("请输入密码：");
            String password = is.nextLine();
            Statement st = conn.createStatement();
            String sql="SELECT id,username,password,nickname,age" +
                    "FROM user" +
                    "WHERE username='"+username+"'"+
                   " AND password='"+password+"'";
            ResultSet count = st.executeQuery(sql);
            if (count.next())
                System.out.println("登录成功！");
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
}
